<template>
  <div id="myChart" style="width: 100%; height: 278px; float: left"></div>
</template>

<script>
import * as echarts from "echarts";
// import { getselectRoomBedSum } from "@/api/system/emporty";
// require("echarts/theme/macarons"); // echarts theme
// import resize from '@/views/dashboard/mixins/resize'
export default {
  name: "checkin",
  // mixins: [resize],
  data() {
    return {
      myChart1: "",
      // roombedSum: [],
    };
  },
  created() {
    // this.selectRoomBedList();
    // window.addEventListener("resize", this.handleResize);
  },
  mounted() {
    window.addEventListener("resize", () => {
      if (this.myChart1) {
        this.myChart1.resize();
      }
    });
  },
  beforeDestroy() {
    if (!this.myChart1) {
      return;
    }
    this.myChart1.dispose();
    this.myChart1 = null;
  },
  destroyed() {
    window.removeEventListener("resize", () => {
      this.myChart1.resize();
    });
  },
  methods: {
    // selectRoomBedList() {
    //   getselectRoomBedSum().then((res) => {
    //     this.roombedSum = res.data.data;
    //     this.$nextTick(() => {
    //       this.drawLine();
    //     });
    //   });
    // },
    // handleResize() {
    //   this.myChart1.resize();
    // },
    drawLine() {
      this.myChart1 = echarts.init(document.getElementById("myChart"));
      // let arr = [];
      // this.roombedSum.forEach((item) => {
      //   arr.push({
      //     value: item.value,
      //     name: item.name,
      //   });
      // });
      this.myChart1.setOption({
        // title:{
        //   x: "45%",     //X坐标
        //   y: "40%",
        //   subtext: "75%",
        //   subtextStyle: {   //副标题样式
        //     fontSize: 26,
        //     fontWeight: "bolder",
        //     color: "#333",
        //     formatter: '',
        //     marginTop:"-50%",
        //     marginLeft:"-50%",
        //     transfrom:"translate(-50%,-50%)"
        //   }
        // },
        title: {
          // text: '75%',
          x: "30%",
          top: "middle",
          textAlign: "center",
          textStyle: {
            fontSize: "25",
            fontWeight: "500",
            color: "#1accac",
            textAlign: "center",
          },
        },
        tooltip: {
          // 只会显示该点的数据
          trigger: "item",
        },
        color: ["#1ad9b6", "#ffdb5c", "#faa140", "#19b9a9"],
        legend: {
          type: "scroll",
          orient: "vertical",
          left: "60%",
          align: "left",
          top: "50%",
          textStyle: {
            color: "#333",
            rich: {
              name: {
                verticalAlign: "right",
                align: "left",
                fontSize: 14,
                color: "#020807",
              },
              percent: {
                padding: [0, 0, 0, 10],
                color: "#020807",
                fontSize: 14,
              },
            },
          },
          formatter: (name) => {
            const item = this.roombedSum.find((i) => {
              return i.name === name;
            });
            const p = item.value;
            return "{name|" + name + "}" + "{percent|" + p + "}";
          },
          height: 250,
        },
        series: [
          {
            name: "宿舍可用床位",
            type: "pie",
            center: ["30%", "60%"],
            radius: ["50%", "70%"],
            avoidLabelOverlap: false,
            // itemStyle: {
            //   borderRadius: 10,
            //   borderWidth: 1,
            //   borderColor: "#fff",
            //   // shadowBlur: 10,
            //   shadowColor: "rgba(0,0,0,0.5)",
            // },
            label: {
              show: false,
              position: "center",
            },
            // emphasis: {
            //   label: {
            //     show: true,
            //     fontSize: 40,
            //     fontWeight: "bold",
            //   },
            // },
            labelLine: {
              show: false,
            },
            data: this.roombedSum,
          },
        ],
      });
    },
  },
};
</script>
<style scoped>

</style>